#include "options.h"
#include "../base/logger.h"

USE_JLIB_NS


int main (int argc, char** argv) {

  Options options {
    {"all", "do not ignore entyies starting with .", Options::NonValue, 'a'},
    {"almost-all", "do not list implied . and ..", Options::NonValue, 'A'},
    {"author", "with -l, print the author of each file", Options::NonValue, 0},
    {"escape", "print C-style escapes for nongraphic characters", Options::NonValue, 'b'},
    {"block-size", "scale sizes by SIZE before printing them; e.g., '--block-size=M' prints sizes in units of 1,048,576 bytes; see SIZE format below", Options::Required, 0},
    {"ignore-backups", "do not list implied entries ending with ~", Options::NonValue, 'B'},
    {nullptr, "with -lt: sort by, and show, ctime (time of last modification of file status information); with -l: show ctime and sort by name; otherwise: sort by ctime, newest first", Options::NonValue, 'c'},
    {nullptr, "list entyies by columns", Options::NonValue, 'C'},
    {"color", "colorize the output; WHEN can be 'always' (default if omitted), 'auto', or 'never'; more info below", 0, 0},
    {"directory", "list directories themselves, not their contents", Options::NonValue, 'd'},
    {"dired", "generate output designed for Emacs' dired mode", Options::NonValue, 'D'},
    {nullptr, "do not sort, enable -aU, disable -ls --color", Options::NonValue, 'f'},
    {"classify", "append indicator (one of */=>@|) to entries", Options::NonValue, 'F'},
    {"file-type", "likewise, except do not append '*'", Options::NonValue, 0},
    {"format", "across -x, commas -m, horizontal -x, long -l, single-column -1, verbose -l, vertical -C", Options::Required, 0},
    {"full-time", "like -l --time-style=full-iso", Options::NonValue, 0},
    {nullptr, "like -l, but do not list owner", Options::NonValue, 'g'},
    {"group-directories-first", "group directories before files; can be augmented with a --sort option, but any use of --sort=none (-U) disables grouping", Options::NonValue, 0},
    {"no-group", "in a long listing, don't print group names", Options::NonValue, 'G'},
    {"human-readable", "with -l and/or -s, print human readable sizes (e.g., 1K 234M 2G)", Options::NonValue, 'h'},
    {"si", "likewise, but use powers of 1000 not 1024", Options::NonValue, 0},
    {"dereference-command-line", "follow symbolic links listed on the command line", Options::NonValue, 'H'},
    {"dereference-command-line-symlink-to-dir", "follow each command line symbolic link that points to a directory", Options::NonValue, 0},
    {"hide", "do not list implied entries matching shell PATTERN (overridden by -a or -A)", Options::Required, 0},
    {"indicator-style", "append indicator with style WORD to entry names: none (default), slash (-p), file-type (--file-type), classify (-F)", 0, 'P'},
    {"inode", "print the index number of each file", Options::NonValue, 'i'},
    {"ignore", "do not list implied entries matching shell PATTERN", Options::Required, 'I'},
    {"kibibytes", "default to 1024-byte blocks for disk usage", Options::NonValue, 'k'},
    {nullptr, "use a long listing format", Options::NonValue, 'l'},
    {"dereference", "when showing file information for a symbolic link, show information for the file the link references rather than for the link itself", Options::NonValue, 'L'},
    {nullptr, "fill width with a comma separated list of entries", Options::NonValue, 'm'},
    {"numeric-uid-gid", "like -l, but list numeric user and group IDs", Options::NonValue, 'n'},
    {"literal", "print raw entry names (don't treat e.g. control characters specially)", Options::NonValue, 'N'},
    {nullptr, "like -l, but do not list group information", Options::NonValue, 'o'},
    {"hide-control-chars", "print ? instead of nongraphic characters", Options::NonValue, 'q'},
    {"show-control-chars", "show nongraphic characters as-is (the default, unless program is 'ls' and output is a terminal)", Options::NonValue, 0},
    {"quote-name", "enclose entry names in double quotes", Options::NonValue, 'Q'},
    {"quoting-style", "use quoting style WORD for entry names: literal, locale, shell, shell-always, shell-escape, shell-escape-always, c, escape", Options::Required, 0},
    {"reverse", "reverse order while sorting", Options::NonValue, 'r'},
    {"recursive", "list subdirectories recursively", Options::NonValue, 'R'},
    {"size", "print the allocated size of each file, in blocks", Options::NonValue, 's'},
    {nullptr, "sort by file size, largest first", Options::NonValue, 'S'},
    {"sort", "sort by WORD instead of name: none (-U), size (-S), time (-t), version (-v), extension (-X)", Options::Required, 0},
    {"time", "with -l, show time as WORD instead of default modification time: atime or access or use (-u); ctime or status (-c); also use specified time as sort key if --sort=time (newest first)", Options::Required, 0},
    {"time-style", "with -l, show times using style STYLE: full-iso, long-iso, iso, locale, or +FORMAT; FORMAT is interpreted like in 'date'; if FORMAT is FORMAT1<newline>FORMAT2, then FORMAT1 applies to non-recent files and FORMAT2 to recent files; if STYLE is prefixed with 'posix-', STYLE takes effect only outside the POSIX locale", Options::Required, 0},
    {nullptr, "sort by modification time, newest first", Options::NonValue, 't'},
    {"tabsize", "assume tab stops at each COLS instead of 8", Options::Required, 'T'},
    {nullptr, "with -lt: sort by, and show access time; with -l: show access time and sort by name; otherwise: sort by access time, newest first", Options::NonValue, 'u'},
    {nullptr, "do not sort; list entries in directory order", Options::NonValue, 'U'},
    {nullptr, "natural sort of (version) numbers within text", Options::NonValue, 'v'},
    {"width", "set output width to COLS. 0 means no limit", Options::Required, 'w'},
    {nullptr, "list entries by lines instead of by columns", Options::NonValue, 'x'},
    {nullptr, "sort alphabetically by entry extension", Options::NonValue, 'X'},
    {"context", "print any security context of each file", Options::NonValue, 'Z'},
    {nullptr, "list one file per line. Avoid '\\n' with -q or -b", Options::NonValue, '1'},
    {"help", "display this help and exit", Options::NonValue, 0},
    {"version", "output version information and exit", Options::NonValue, 0}
  };

  options(argc, argv);
  
  log_i("Flags:");
  if (options("all"))
    log_d("\t-a, --all");
  if (options("almost-all"))
    log_d("\t-A, --almost-all");
  if (options("author"))
    log_d("\t--author");
  if (options("escape"))
    log_d("\t-b, --escape");
  if (options("ignore-backups"))
    log_d("\t-B, --ignore-backups");
  if (options('c'))
    log_d("\t-c");
  if (options('C'))
    log_d("\t-C");
  if (options("directory"))
    log_d("\t-d, --directory");
  if (options("dired"))
    log_d("\t-D, --dired");
  if (options('f'))
    log_d("\t-f");
  if (options("classify"))
    log_d("\t-F, --classify");
  if (options("file-type"))
    log_d("\t--file-type");
  if (options("full-time"))
    log_d("\t--full-time");
  if (options('g'))
    log_d("\t-g");
  if (options("group-directories-first"))
    log_d("\t--group-directories-first");
  if (options("no-group"))
    log_d("\t-G, --no-group");
  if (options("human-readable"))
    log_d("\t-h, --human-readable");
  if (options("si"))
    log_d("\t--si");
  if (options('H'))
    log_d("\t-H, --dereference-command-line");
  if (options("dereference-command-line-symlink-to-dir"))
    log_d("\t--dereference-command-line-symlink-to-dir");
  if (options("inode"))
    log_d("\t-i, --inode");
  if (options('k'))
    log_d("\t-k, --kibibytes");
  if (options('l'))
    log_d("\t-l");
  if (options('L'))
    log_d("\t-L, --dereference");
  if (options('m'))
    log_d("\t-m");
  if (options('n'))
    log_d("\t-n, --numeric-uid-gid");
  if (options('N'))
    log_d("\t-N, --literal");
  if (options('o'))
    log_d("\t-o");
  if (options('q'))
    log_d("\t-q, --hide-control-chars");
  if (options("show-control-chars"))
    log_d("\t--show-control-chars");
  if (options('Q'))
    log_d("\t-Q, --quote-name");
  if (options('r'))
    log_d("\t-r, --reverse");
  if (options('R'))
    log_d("\t-R, --recursive");
  if (options('s'))
    log_d("\t-s, --size");
  if (options('S'))
    log_d("\t-S");
  if (options('t'))
    log_d("\t-t");
  if (options('u'))
    log_d("\t-u");
  if (options('U'))
    log_d("\t-U");
  if (options('v'))
    log_d("\t-v");
  if (options('x'))
    log_d("\t-x");
  if (options('X'))
    log_d("\t-X");
  if (options('Z'))
    log_d("\t-Z, --context");
  if (options('1'))
    log_d("\t-1");
  if (options("help"))
    log_d("\t--help");
  if (options("version"))
    log_d("\t--version");

  log_i("Parameter:");
  if (options("block-size"))
    log_d("\t--block-size: %s", options["block-size"]);
  if (options("color"))
    log_d("\t--color: %s", options["color"]);
  if (options("format"))
    log_d("\t--format: %s", options["format"]);
  if (options("hide"))
    log_d("\t--hide: %s", options["hide"]);
  if (options("indicator-style"))
    log_d("\t-P, --indicator-style: %s", options["indicator-style"]);
  if (options('I'))
    log_d("\t-I, --ignore: %s", options['I']);
  if (options("quoting-style"))
    log_d("\t--quoting-style: %s", options["quoting-style"]);
  if (options("sort"))
    log_d("\t--sort: %s", options["sort"]);
  if (options("time"))
    log_d("\t--time: %s", options["time"]);
  if (options("time-style"))
    log_d("\t--time-style: %s", options["time-style"]);
  if (options('T'))
    log_d("\t-T, --tabsize: %s", options['T']);
  if (options('w'))
    log_d("\t-w, --width: %s", options['w']);
}
